﻿using AutoMapper;
using ERPSystem.Common.Domains.Notices;
using ERPSystem.Common.DTO;
using ERPSystem.Enum.CommonErrorCodes;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using NPOI.SS.Formula.Functions;
using SalesManagementWrite.API.SalesManagementWrites.BillingInvoicing;
using Yitter.IdGenerator;

namespace SalesManagementWrite.API.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class BilleInvoiceController : ControllerBase
    {
        private readonly IMediator _mediator;

        public BilleInvoiceController(IMediator mediator)
        {
            _mediator = mediator;
        }

        /// <summary>
        /// 开票通知单添加
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpPost]
        public async Task<Result> CreateInvoice(BillingInvoicingCreateCommon request, CancellationToken cancellationToken)
        {
            request.Documentsnumber = "KPTZD" +YitIdHelper.NextId().ToString();
            return await _mediator.Send(request, cancellationToken);
        }

        /// <summary>
        /// 开票物料新增
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpPost]
        public async Task<Result> CreateBilleMater(BillInvoiceMaterCommon request, CancellationToken cancellationToken)
        {
            return await _mediator.Send(request, cancellationToken);
        }
    }
}
